<?php
    include APPLICATION_PATH . '/application/views/head.phtml';
    include APPLICATION_PATH . '/application/views/top.phtml';
    include APPLICATION_PATH . '/application/views/left.phtml';
?>
<script src="/public/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script>
    $(document).ready(function() {
    var __addForm = $('#form_add'),
        __editForm = $('#form_edit');
    $('#submit_form').click(function() {
        var objForm = {
            __formName: $("select[name='name']", __addForm),
            /*__formPlan: $("input[name='plan']", __addForm),*/
            __formType: $("select[name='article_type_id']", __addForm),
            __formStatus: $("select[name='status']", __addForm),
            __formTime: $("input[name='create_time']", __addForm),
            __formEnds: $("input[name='end_time']", __addForm),
            __formRemark: $("textarea[name='remark']", __addForm)
        };
        function CompareDate(d1,d2){
            return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
        } 

var starTime =objForm.__formTime.val();
var endTime = objForm.__formEnds.val();
//    layer.alert("结束时间必须大于开始时间");
        if ('--请选择要采集的名称--' == objForm.__formName.val()) {
            layer.alert('请选择要采集的名称');
            return false;
        }

       /*if ('' == objForm.__formPlan.val()) {
            layer.alert('计划不能为空！');
            return false;
        }*/
        //CheckUrl();
        function getCurrentTime(){
            var currentDate = new Date();
            var odata = {};
            odata.y = currentDate.getFullYear();
            odata.m = currentDate.getMonth()+1;
            odata.d = currentDate.getDate();
            odata.h = currentDate.getHours();
            odata.ms = currentDate.getMinutes();
            odata.s = currentDate.getSeconds();
            return odata.y + '-' + odata.m + '-' + odata.d + ' ' + odata.h + ':' + odata.ms + ':' + odata.s;
        }
        if('' == starTime || '' == endTime){
            layer.alert('请输入采集时间');
            return false;
        }
        if(CompareDate(getCurrentTime(), starTime)){
            layer.alert("开始时间必须大于当前时间");
            return false;
        }
        if(CompareDate(starTime, endTime)){
            layer.alert("结束时间必须大于开始时间");
            return false;
        }

        $.ajax({
            type: "POST",
            url: "/Plan/add",
            data: {
                "source_id": objForm.__formName.val(),
/*                "plan_source": 　objForm.__formPlan.val(),
                "article_type_id": 　objForm.__formType.val(),*/
                "status": 　objForm.__formStatus.val(),
                "create_time": 　objForm.__formTime.val(),
                "end_time": 　objForm.__formEnds.val(),
                "remark": 　objForm.__formRemark.val()
            },
            success: function(data) {
                layer.alert(data.info, function() {
                    if (true === data.status) window.location = "/Plan/list";
                });
            }
        });

    });

    //$('.itemDelete').click(function(){
    $(document).on('click', '.tableDelete', function() {
        var userId = $(this).parent('td').attr('item_id'),
            thisUrl = $(this).attr('href');
        //官网欢迎页   
        layer.confirm('确认删除', {
            btn: ['确认', '取消'] //按钮
        }, function(index) {

            $.ajax({
                type: "GET",
                url: thisUrl,
                async: true,
                data: {
                    //"id" : userId
                },
                success: function(data) {
                    layer.alert(data.info, function() {
                        if (true === data.status) window.location = "/Plan/list";
                    });
                }
            });
            layer.close(index);
            return false;

        }, function(index) {
            layer.close(index);
        });
        return false;

    });


    //$('.itemEdit').click(function(e){
    $(document).on('click', '.tableEdit', function(e) {
        $('#form_edit').modal("toggle");
        item_id = $(this).parent('td').attr('item_id');
        current_status = $(this).parent('td').attr('status');
        current_site = $(this).parent('td').attr('source_id');
       
        var __parent = $(this).parent('td').parent('tr.gradeX'),
            __formName = $("select[name='source_name']", __editForm),
           /* __formPlan = $("input[name='plan']", __editForm),
            __formType = $("select[name='article_type_id']", __editForm),*/
            __formStatus = $("select[name='status']", __editForm),
            __formTime = $("input[name='create_time']", __editForm),
            __formEnds = $("input[name='end_time']", __editForm),
            __formRemark = $("textarea[name='remark']", __editForm);
        var tdTable = [];
        $('td', __parent).each(function() {
            tdTable.push($(this).text());
        });
        __formName.val(current_site);
/*        __formPlan.val(tdTable[1]);
        __formType.val(current_type);*/
        __formStatus.val(current_status);
        __formRemark.val(tdTable[2]);
        __formTime.val(tdTable[3]);
        __formEnds.val(tdTable[4]);
        return false;
    });


    $('#edit_form').click(function() {
        var objForm = {
            __formName: $("select[name='source_name']", __editForm),
/*            __formPlan: $("input[name='plan']", __editForm),
            __formType: $("select[name='article_type_id']", __editForm),*/
            __formStatus: $("select[name='status']", __editForm),
            __formTime: $("input[name='create_time']", __editForm),
            __formEnds: $("input[name='end_time']", __editForm),
            __formRemark: $("textarea[name='remark']", __editForm)
        }

        $.ajax({
            type: "POST",
            url: "/Plan/edit/id/" + item_id,
            data: {
                "name": objForm.__formName.val(),
               /* "plan_source": 　objForm.__formPlan.val(),
                "article_type_id": 　objForm.__formType.val(),*/
                "status": 　objForm.__formStatus.val(),
                "create_time": 　objForm.__formTime.val(),
                "end_time": 　objForm.__formEnds.val(),
                "remark": 　objForm.__formRemark.val()
            },
            success: function(data) {
                layer.alert(data.info, function() {
                    if (true === data.status) window.location = "/Plan/list";
                });
            }
        });

    })

    $(document).on('click', '#page_next,#page_prev,#page_index,#page_end', function() {
        var urlOld = $(this).attr('href'),
            urlArr = urlOld.split("/");
        urlId = urlArr[urlArr.length - 1];
        $.ajax({
            type: 'POST',
            url: '/Plan/page/page/' + urlId,
            data: urlId,
            success: function(data) {
                var data = $.parseJSON(data);

                $('#tbody').html('');
                var id = '';

                $.each(data, function(k, v) {
                    //console.log('k='+k);
                    id = v['id'];
                    article_type_id = v['article_type_id'];

                    $('#tbody').append($('<tr class="gradeX"><td>' + v['source_name'] + '</td><td>' + v['plan_status'] + '</td><td>' + v['remark'] + '</td><td>' + v['current_time'] + '</td><td>' + v['ends_time'] + '</td><td status="' + v['status'] + '"  item_id="' + v['id'] + '" article_type_id="' + article_type_id + '" ><a class="tableDelete" href="/Plan/del/id/' + id + '">删除</a> / <a class="tableEdit" href="/Plan/edit/id/' + id + '">修改</a> </td></tr>'));


                });


            }

        });
        $.ajax({
            type: 'POST',
            url: '/Plan/currentPage/page/' + urlId,
            data: urlId,
            success: function(data) {
                //console.log(data);
                $('#pages').html(data);
                $('#pages').ready(function() {
                    nextBtn = $('#page_next');
                });
            }

        });
        return false;
    });

});
</script>
 <div id="thispage" data-id="43"></div>
       <!-- BEGIN PAGE -->

        <div class="page-content">

            <!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->

            <div id="portlet-config" class="modal hide">

                <div class="modal-header">

                    <button data-dismiss="modal" class="close" type="button"></button>

                    <h3>portlet Settings</h3>

                </div>

                <div class="modal-body">

                    <p>Here will be a configuration form</p>

                </div>

            </div>

            <!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->

            <!-- BEGIN PAGE CONTAINER-->        

            <div class="container-fluid">

                <!-- BEGIN PAGE HEADER-->

                <div class="row-fluid">

                    <div class="span12">

                        <!-- BEGIN STYLE CUSTOMIZER -->

                        <div class="color-panel hidden-phone">

                            <!-- <div class="color-mode-icons icon-color"></div> -->

                            <div class="color-mode-icons icon-color-close"></div>

                            <div class="color-mode">

                                <p>THEME COLOR</p>

                                <ul class="inline">

                                    <li class="color-black current color-default" data-style="default"></li>

                                    <li class="color-blue" data-style="blue"></li>

                                    <li class="color-brown" data-style="brown"></li>

                                    <li class="color-purple" data-style="purple"></li>

                                    <li class="color-grey" data-style="grey"></li>

                                    <li class="color-white color-light" data-style="light"></li>

                                </ul>

                                <label>

                                    <span>Layout</span>

                                    <select class="layout-option m-wrap small">

                                        <option value="fluid" selected>Fluid</option>

                                        <option value="boxed">Boxed</option>

                                    </select>

                                </label>

                                <label>

                                    <span>Header</span>

                                    <select class="header-option m-wrap small">

                                        <option value="fixed" selected>Fixed</option>

                                        <option value="default">Default</option>

                                    </select>

                                </label>

                                <label>

                                    <span>Sidebar</span>

                                    <select class="sidebar-option m-wrap small">

                                        <option value="fixed">Fixed</option>

                                        <option value="default" selected>Default</option>

                                    </select>

                                </label>

                                <label>

                                    <span>Footer</span>

                                    <select class="footer-option m-wrap small">

                                        <option value="fixed">Fixed</option>

                                        <option value="default" selected>Default</option>

                                    </select>

                                </label>

                            </div>

                        </div>

                        <!-- END BEGIN STYLE CUSTOMIZER -->  

                        <!-- BEGIN PAGE TITLE & BREADCRUMB-->

                        <h3 class="page-title">

                            采集计划列表
                        </h3>

                        <ul class="breadcrumb">

                            <li>

                                <i class="icon-home"></i>
                                <span>当前位置：</span>
                                <span>首页</span>

                                <i class="icon-angle-right"></i>

                            </li>

                            <li>

                                <span>采集管理</span>

                                <i class="icon-angle-right"></i>

                            </li>

                            <li><span>采集计划列表</span></li>

                        </ul>

                        <!-- END PAGE TITLE & BREADCRUMB-->

                    </div>

                </div>

                <!-- END PAGE HEADER-->

                <!-- BEGIN PAGE CONTENT-->

                <div class="row-fluid">

                    <div class="span6 responsive" data-tablet="span12 fix-offset" data-desktop="span6" style="width:100%;">

                        <!-- BEGIN EXAMPLE TABLE PORTLET-->

                        <div class="portlet box grey">

                            <div class="portlet-title">

                                <div class="caption"><i class="icon-user"></i>采集计划列表</div>

                                <div class="actions controls">

                                    <a href="#form_modal_tj"  data-toggle="modal" data-target="#form_modal_tj" class="btn blue"><i class="icon-pencil"></i> 添加</a>
                                    <!--<a href="/Index/Authority/add" class="btn blue"><i class="icon-pencil"></i> 添加</a>-->

                                </div>

                            </div>

                            <div class="portlet-body">

                                <table class="table table-striped table-bordered table-hover" id="current_table">

                                    <thead>

                                        <tr>
                                            <!--<th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#sample_2 .checkboxes" /></th>-->
                                            <th>计划名称</th>
                                            <th>是否有效</th>
                                            <th>描述</th>
                                            <th>开始时间</th>
                                            <th>结束时间</th>
                                            <th>操作</th>
                                        </tr>

                                    </thead>

                                    <tbody id="tbody">
<?php
    foreach ($collplan_list as $k => $v) {
        $style  = (0 == ($k % 2)) ? 'odd' : 'even';
        $status = empty($v['status']) ? '否' : '是';
        //$create_time = date('Y-m-d H:i:s', (int) $v['create_time']);
        echo <<< EOF
                                        <tr class="{$style} gradeX">

                                            <td>{$v['source_name']}</td>
                                            <td>{$status}</td>
                                            <td>{$v['remark']}</td>
                                            <td>{$v['current_time']}</td>
                                            <td>{$v['ends_time']}</td>
                                            <td item_id="{$v['id']}" status="{$v['status']}" source_id="{$v['source_id']}" ><a class="tableDelete" href="/Plan/del/id/{$v['id']}">删除</a> / <a  class="tableEdit" href="/Plan/edit/id/{$v['id']}">修改</a></td>
                                        </tr>
EOF;
    }
?>
                                    </tbody>

                </table>
<div id="pages">
<?php
    if($collplan_list[0]['rows']/$collplan_list[0]['every_page']<=1 || empty($collplan_list))
        {
            
        }
        else
        {
            print_r($allpage);
        }
?>
</div>

                            </div>

                        </div>
                        
                                <div id="form_modal_tj" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

                                    <div class="modal-header">

                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

                                        <h3 id="myModalLabel3">添加采集计划</h3>

                                    </div>

                                    <div class="modal-body">

                                        <form action="#" id="form_add" method="post" class="form-horizontal">

                                            <div class="control-group">

                                                <label class="control-label">计划名称</label>

                                                <div class="controls">

                                                    <!-- <input type="text" class="colorpicker-default m-wrap" name="name" value=""> -->
                                                    <select name="name">
                                                        <option>--请选择要采集的名称--</option>
                                                        
<?php 
    foreach ($source_list AS $k => $v) {
        echo '<option value="' . $v['source_id'] . '">' . $v['name'] . '</option>';
    }
?>
                                                    </select>

                                                </div>

                                            </div>

                                            <div class="control-group">

                                                <label class="control-label">是否有效</label>

                                                <div class="controls">
                            <select id="status" name="status">
                                <option value="1" checked="checked">有效</option>
                                <option value="0">无效</option>
                            </select>
                                                </div>

                                            </div>

                                            <div class="control-group">

                                                <label class="control-label">开始时间</label>

                                                <div class="controls">

                                                    <!-- <input type="text" class="colorpicker-default m-wrap" name="create_time" value=""> -->

                                                    <input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name="create_time">

                                                </div>

                                            </div>
                                            <div class="control-group">

                                                <label class="control-label">结束时间</label>

                                                <div class="controls">

                                                    <!-- <input type="text" class="colorpicker-default m-wrap" name="create_time" value=""> -->

                                                    <input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name="end_time">

                                                </div>

                                            </div>
                      
                      <div class="control-group">

                                                <label class="control-label">描述</label>

                                                <div class="controls">

                        <textarea name="remark" class="colorpicker-default m-wrap"></textarea>

                                                </div>

                                            </div>                                          

                                        </form>

                                    </div>

                                    <div class="modal-footer">

                                        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

                                        <button class="btn green btn-primary" id="submit_form" data-dismiss="modal" >提交</button>
                                        
                                    </div>

                                </div>
                                
                                <div id="form_edit" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">

                                    <div class="modal-header">

                                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>

                                        <h3 id="myModalLabel3">修改采集计划</h3>

                                    </div>

                                    <div class="modal-body">

                                        <form action="#" id="form_edit" method="post" class="form-horizontal">


                                            <div class="control-group">

                                                <label class="control-label">计划名称</label>

                                                <div class="controls">

                                                   <!--  <input type="text" class="colorpicker-default m-wrap" name="name" value=""> -->
                                                    <select  name="source_name"> -->
<?php
    foreach ($source_list AS $k => $v) {
        echo '<option value="' . $v['source_id'] . '">' . $v['name'] . '</option>';
    }
?> 
                                                    </select>

                                                </div>

                                            </div>

                                            <!-- <div class="control-group">

                                                <label class="control-label">计划采集源</label>

                                                <div class="controls">

                                                    <input type="text" class="colorpicker-default m-wrap" name="plan" value="">

                                                </div>

                                            </div>
                                            <div class="control-group">

                                                <label class="control-label">分类</label>

                                                <div class="controls">
                                                    <select id="article_type_id" name="article_type_id"> -->
<?php
    /*foreach ($articletype_list AS $k => $v) {
        echo '<option value="' . $v['article_type_id'] . '">' . $v['name'] . '</option>';
    }*/
?><!-- 
                                                    </select>
                                                </div>

                                              </div> -->

                                            <div class="control-group">

                                                <label class="control-label">是否有效</label>

                                                <div class="controls">
                            <select id="status" name="status">
                                <option value="1">有效</option>
                                <option value="0">无效</option>
                            </select>
                                                </div>

                                            </div>

                                            <div class="control-group">

                                                <label class="control-label">开始时间</label>

                                                <div class="controls">

                                                    <!-- <input type="text" class="colorpicker-default m-wrap" name="create_time" value=""> -->

                                                    <input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name="create_time">

                                                </div>

                                            </div>
                                            <div class="control-group">

                                                <label class="control-label">结束时间</label>

                                                <div class="controls">

                                                    <!-- <input type="text" class="colorpicker-default m-wrap" name="create_time" value=""> -->

                                                    <input placeholder="请输入日期" class="laydate-icon" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  name="end_time">

                                                </div>

                                            </div>
                      
                      <div class="control-group">

                                                <label class="control-label">描述</label>

                                                <div class="controls">

                        <textarea name="remark" class="colorpicker-default m-wrap"></textarea>

                                                </div>

                                            </div>

                                        </form>

                                    </div>

                                    <div class="modal-footer">

                                        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>

                                        <button class="btn green btn-primary" id="edit_form" data-dismiss="modal" >提交</button>
                                        
                                    </div>

                                </div>

                        <!-- END EXAMPLE TABLE PORTLET-->

                    </div>

                </div>

                <!-- END PAGE CONTENT-->

            </div>

            <!-- END PAGE CONTAINER-->

        </div>

    <!-- END PAGE -->
<?php
    include APPLICATION_PATH . '/application/views/foot.phtml';
?>
